<?php

interface Manager 
{
	public function existStore($key);
	public function getStore($key); 
	public function setStore($key, $value, array $options = array()); 

}

abstract class AbstractManager implements Manager 
{

	protected $arrayObject;
	
	public function __construct(array $array = array()) 
	{
		$this->arrayObject = new ArrayObject($array);
	}
	
	public function existStore($key)
	{
		return $this->arrayObject->offsetExists($key);
	}
	
	public function getStore($key) 
	{
		if($this->arrayObject->offsetExists($key))
			return $this->arrayObject->offsetGet($key);
			
		return false;
	}
	
	public function setStore($key, $value, array $options = array()) 
	{
		return $this->arrayObject->offsetSet($key, $value);
	}

}

class SessionManager extends AbstractManager  
{

	public function __construct() 
	{
		parent::__construct($_SESSION);
	}
	
	public function destroySession()
	{
		$_SESSION = array();
		$this->arrayObject = new ArrayObject($_SESSION);
		session_destroy();
	}
	
	public function getId()
	{
		return session_id();
	}

}

class CookieManager extends AbstractManager 
{

	public function __construct() 
	{
		parent::__construct($_COOKIE);
	}
	
	public function setStore($key, $value, array $options = array('expiry' => 120)) 
	{
		setcookie($key, $value, (time() + $options['expiry']));
	}

}

class PostManager extends AbstractManager  
{

	public function __construct() 
	{
		parent::__construct($_POST);
	}
	
}

class GetManager extends AbstractManager  
{

	public function __construct() 
	{
		parent::__construct($_GET);
	}
	
}


/*
PRZYKLAD
$cookieManager = new CookieManager();

$cookieManager->setStore('logged', true); // ciastko na 60 sekund

if($cookieManager->getStore('logged') === true)  
{
	echo 'Zalogowano';
}

*/
?>